<?php

define('PATH_ERR', __DIR__ . '/errcode.php');

if (!function_exists('backapi')) {

    function backapi($code = 0, $data = NULL) {
        $err = include PATH_ERR;
        $arr = array(
            'errcode' => $code,
            'errmsg' => isset($err[$code]) ? $err[$code] : '未知错误',
            'data' => $data,
        );
        exit(json_encode($arr));
    }

}

if (!function_exists('backpage')) {

    function backpage($code = 1, $islink = FALSE, $url = '') {
        $err = include PATH_ERR;
        $msg = isset($err[$code]) ? $err[$code] : '未知错误';
        if ($islink) {
            if (framework_static_common::str_empty($url)) {
                exit("<script>alert('{$msg}');history.back(-1);location.href = document.referrer;</script>");
            } else {
                exit("<script>alert('{$msg}');location.href = '{$url}';</script>");
            }
        } else {
            exit("<script>alert('{$msg}');</script>");
        }
    }

}

